{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2088cd38",
   "metadata": {},
   "source": [
    "-----\n",
    "* 记录人：lz\n",
    "* 时间：2021-11-15\n",
    "* week12\n",
    "* 线上学习资源[]()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0ee8c79",
   "metadata": {},
   "source": [
    "## 本周知识点----字典的方法 & 字典的实践\n",
    "\n",
    "### 1.字典的一般方法\n",
    "  \n",
    "> 1.字典的查询   查询key -> value\n",
    ">> 1. 先看字典的key是否存在：in查询成员是否存在的重要方法\n",
    ">> 2.查询\n",
    "> 2.字典的修改  \n",
    "> 3. 字典的删除  \n",
    "> 4.字典的增加（dict_name[key]=value）\n",
    "\n",
    "### 2.字典的进阶方法\n",
    "\n",
    "> 1.字典的初始化\n",
    ">> 1.dict.fromkeys()  \n",
    ">> 2.dict.setdefault()  \n",
    "\n",
    "### 3.字典的实践（一）课本  \n",
    "\n",
    "### 4.字典的实践（二）课本  \n",
    "\n",
    "### 5.字典的实践（三）课本\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6aab61ec",
   "metadata": {},
   "source": [
    "### 1.字典的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5f63ceb1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1801': 'cc', 'stu1802': 'vv', 'stu1803': 'dd'}\n"
     ]
    }
   ],
   "source": [
    "stu_info = {\n",
    "    \"stu1801\":\"cc\",\n",
    "    \"stu1802\":\"vv\",\n",
    "    \"stu1803\":\"dd\"\n",
    "}\n",
    "print(stu_info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed3c2888",
   "metadata": {},
   "source": [
    "> 1.字典的查询\n",
    ">> 1.直接查找 dict_name[key]  当关键词不存在时，报错： KeyError: 'stu1804'   \n",
    ">> 2.get()方法 dict.get(k[,d]) 当关键词key不存在时返回None，不会报错\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ada40165",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'vv'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 直接查找\n",
    "stu_info[\"stu1802\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9112ef66",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'stu1804'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-5-af87bde9363c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mstu_info\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"stu1804\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m: 'stu1804'"
     ]
    }
   ],
   "source": [
    "stu_info[\"stu1804\"]    # 没找到所以报错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "eea3d334",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function get:\n",
      "\n",
      "get(key, default=None, /) method of builtins.dict instance\n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 使用get方法查找\n",
    "help(stu_info.get)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3d16cf37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cc'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info.get(\"stu1801\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ac24aaf8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(stu_info.get(\"stu1805\"))   # 查找不到，所以返回None"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc6eadf4",
   "metadata": {},
   "source": [
    "> 2. 修改&新增\n",
    ">> 1.先查询 查看key是否存在 使用in 查询成员  \n",
    ">> 2.如果key存在 修改：dict_name[key]=value  \n",
    ">> 3.如果key不存在 新增：dict_name[key]=value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "87811e7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查询 stu1804\n",
    "\"stu1804\" in stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7c95bd4c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查询stu1803\n",
    "\"stu1803\" in stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6534b2c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'cc', 'stu1802': 'vv', 'stu1803': 'nn'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 如果key存在 修改\"stu1803\":\"dd\" --> \"stu1803\":\"nn\"\n",
    "if \"stu1803\" in stu_info:\n",
    "    stu_info[\"stu1803\"] = \"nn\"\n",
    "stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "b8575f2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'cc', 'stu1802': 'vv', 'stu1803': 'dd', 'stu1804': 'pp'}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 如果key不存在就无法修改 返回后还是原来的列表 ，所以要先增加 再修改\n",
    "stu_info[\"stu1804\"] = \"kk\"   # ---》增加\n",
    "if \"stu1804\" in stu_info:\n",
    "    stu_info['stu1804'] = \"pp\"\n",
    "stu_info"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fce3bc91",
   "metadata": {},
   "source": [
    "> 3. 字典的删除\n",
    "\n",
    ">> 1.dict,pop() --根据key删除对应的value,即可以删除指定值  \n",
    ">>> 1.先查询是否存在 in   \n",
    ">>> 2.再使用删除的方法  \n",
    "\n",
    ">> 2.dict.popitem() --删除字典中随机一对key-value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1b8c5d5c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(...) method of builtins.dict instance\n",
      "    D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n",
      "    If key is not found, d is returned if given, otherwise KeyError is raised\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stu_info.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1407676a",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "pop expected at least 1 argument, got 0",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-16-01f9bb0f3b2e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mstu_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m  \u001b[1;31m# 不正确，不同于列表 字典时无序的，所以字典没有这种用法来删除\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: pop expected at least 1 argument, got 0"
     ]
    }
   ],
   "source": [
    "stu_info.pop()  # 不正确，不同于列表 字典时无序的，所以字典没有这种用法来删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "22ede086",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'nn'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字典删除的正确使用\n",
    "if \"stu1803\" in stu_info:\n",
    "    stu_info.pop(\"stu1803\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f2e6cac1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'cc', 'stu1802': 'vv'}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info    # 这是删除后的字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c37702d2",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'stu1804'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-2-0c6641a627a2>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 如果不先查询 key是否存在，有可能会报错：NameError: name 'stu1804' is not defined\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mstu_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'stu1804'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m: 'stu1804'"
     ]
    }
   ],
   "source": [
    "# 如果不先查询 key是否存在，有可能会报错：KeyError: 'stu1804'\n",
    "stu_info.pop('stu1804')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "1fa48ef1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function popitem:\n",
      "\n",
      "popitem() method of builtins.dict instance\n",
      "    Remove and return a (key, value) pair as a 2-tuple.\n",
      "    \n",
      "    Pairs are returned in LIFO (last-in, first-out) order.\n",
      "    Raises KeyError if the dict is empty.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(stu_info.popitem)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "bbb3b573",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('stu1802', 'vv')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info.popitem()    # 随机删除字典中的任意一个 所以具有不确定性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "66b7a875",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'cc'}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acfcda8b",
   "metadata": {},
   "source": [
    "### 3.字典的实践（一）课本\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af983cb0",
   "metadata": {},
   "source": [
    "```\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    " \n",
    " # found[\"a\"]=0\n",
    " # found[\"e\"]=0\n",
    " # found[\"i\"]=0\n",
    " # found[\"o\"]=0\n",
    " # found[\"u\"]=0\n",
    "found = found.fromkeys(vowels,0)\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "         found[letter] += 1\n",
    " \n",
    " # print(found.items())\n",
    "for k,v in found.items():\n",
    "     print(k,\"was found\",v,\"time(s)\")\n",
    "# print(found)\n",
    "\n",
    "vowels4\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "cd283f30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:hellowjuihhyh\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'a': 0, 'e': 1, 'i': 1, 'o': 1, 'u': 1}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 目标：查询元音字母是否出现在word文本中，并且统计出现的次数\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    "\n",
    "# 字典初始化 的值\n",
    "# found[\"a\"]=0\n",
    "# found[\"e\"]=0\n",
    "# found[\"i\"]=0\n",
    "# found[\"o\"]=0\n",
    "# found[\"u\"]=0\n",
    "\n",
    "for i in vowels:\n",
    "    # 使用字典的新增  构建初始化字典\n",
    "    found[i] = 0\n",
    "    \n",
    "# 循环用户输入的文本，出现一次元音字母，对应的元音字母就+1\n",
    "for i in word:\n",
    "    if i in vowels:\n",
    "        found[i] +=1  # 出现一次就自加1\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04c4c162",
   "metadata": {},
   "source": [
    "> 字典的进阶方法：初始化所有的值 用 fromkeys()\n",
    ">>  用法： fromkeys(dict,value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "9db7bafa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function fromkeys:\n",
      "\n",
      "fromkeys(iterable, value=None, /) method of builtins.type instance\n",
      "    Create a new dictionary with keys from iterable and values set to value.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.fromkeys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c70fde75",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a': None, 'e': None, 'i': None, 'o': None, 'u': None}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "found = {}\n",
    "found = found.fromkeys(vowels)       # 如果不写初始化的值，就会默认所有的对象初始对应的值都为：None\n",
    "found          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "32ffe045",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:duwhuhyewdwyffaaadfg\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'a': 3, 'e': 1, 'i': 0, 'o': 0, 'u': 2}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    "# 初始化 字典\n",
    "found = found.fromkeys(vowels,0)\n",
    "for i in word:\n",
    "    if i in vowels:\n",
    "        found[i] +=1\n",
    "found          "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "491e731b",
   "metadata": {},
   "source": [
    "> 字典的进阶方法：初始化特定的值 方法 setdefault()\n",
    "\n",
    ">> * 查询 key 是否出现在字典中\n",
    ">>> 1. 出现过，就当没看见，不做任何操作\n",
    ">>> 2. key未出现过，给出指定key及value（指定的初始化的值）就可以对未出现过的对象进行初始化值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3863986a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function setdefault:\n",
      "\n",
      "setdefault(key, default=None, /) method of builtins.dict instance\n",
      "    Insert key with a value of default if key is not in the dictionary.\n",
      "    \n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(found.setdefault)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "d5847289",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_password = {\n",
    "    \"xiaoming\":\"121212\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "818fc11d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'123456'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_password.setdefault(\"lihua\",\"123456\")    # 没出过"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "b65173d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'121212'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_password.setdefault(\"xiaoming\",\"123456\")   # 出现过"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "b9ab5faa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'123456'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_password.setdefault(\"xiaojie\",\"123456\")   # 没出过"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0962ccbe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'xiaoming': '121212', 'lihua': '123456', 'xiaojie': '123456'}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_password    # 字典的最终效果"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27f72cc7",
   "metadata": {},
   "source": [
    "### 4. 字典的实践（二）课本"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "745f674c",
   "metadata": {},
   "source": [
    "```\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    " \n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        found.setdefault(letter,0)  #如果是元音字母，就在字典found中初始化这个元音字母，值为0\n",
    "         found[letter] +=1\n",
    "for k,v in sorted(found.items()):\n",
    "     print(k,v)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0935ed7e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:hellow i am supperise\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'e': 3, 'o': 1, 'i': 2, 'a': 1, 'u': 1}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 优化： 实践一\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    "\n",
    "for i in word:\n",
    "    if i in vowels:\n",
    "        found.setdefault(i,0)\n",
    "        found[i] +=1\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6dc526bc",
   "metadata": {},
   "source": [
    "### 5.字典的实践（三）课本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "84586538",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Ford': {'Name': 'Ford Prefect',\n",
       "  'Gender': 'Male',\n",
       "  'Occupation': 'Researcher',\n",
       "  'Home Planet': 'Betelgeuse Seven'},\n",
       " 'Arthur': {'Name': 'Arthur Dent',\n",
       "  'Gender': 'Male',\n",
       "  'Occupation': 'Sandwich-Maker',\n",
       "  'Home Planet': 'Earth'},\n",
       " 'Tricia': {'Name': 'Tricia McMillan',\n",
       "  'Gender': 'Female',\n",
       "  'Occupation': 'Mathematician',\n",
       "  'Home Planet': 'Earth'},\n",
       " 'Marvin': {'Name': 'Marvin',\n",
       "  'Gender': 'Unknown',\n",
       "  'Occupation': 'Paranoid Android',\n",
       "  'Home Planet': 'Unknown'}}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people = {}\n",
    "people['Ford'] = {\"Name\":'Ford Prefect',\n",
    "                  \"Gender\":'Male',\n",
    "                  \"Occupation\":'Researcher',\n",
    "                  \"Home Planet\":'Betelgeuse Seven'}\n",
    "people['Arthur'] = {\"Name\":'Arthur Dent',\n",
    "                  \"Gender\":'Male',\n",
    "                  \"Occupation\":'Sandwich-Maker',\n",
    "                  \"Home Planet\":'Earth'}\n",
    "people['Tricia'] = {\"Name\":'Tricia McMillan',\n",
    "                    \"Gender\":'Female',\n",
    "                    \"Occupation\":'Mathematician',\n",
    "                    \"Home Planet\":'Earth'}\n",
    "people['Marvin'] = {\"Name\":'Marvin',\n",
    "                    \"Gender\":'Unknown',\n",
    "                    \"Occupation\":'Paranoid Android',\n",
    "                    \"Home Planet\":'Unknown'}\n",
    "people"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ef53d5b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Tricia McMillan'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 任务： 查找并取值 'Tricia McMillan'\n",
    "people['Tricia']['Name']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d810a45",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
